﻿using Hr.IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Hr.BLL
{
    public abstract partial class BaseService<T> where T:class,new()
    {
        public BaseService()
        {
            SetDal();
        }
        public IBaseDAL<T> Dal { get; set; }

        public abstract void SetDal();

        #region 添加
        public bool Add(T t)
        {
            Dal.Add(t);
            return Dal.SaveChanges();
        }
        #endregion

        public bool Delete(T t)
        {
            Dal.Delete(t);
            return Dal.SaveChanges();
        }

        public bool Update(T t)
        {
            Dal.Update(t);
            return Dal.SaveChanges();
        }

        public IQueryable<T> GetModels(Expression<Func<T,bool>> whereLambda)
        {
            return Dal.GetModels(whereLambda);
        }

        public IQueryable<T> GetModelsByPage<type>(int page,int limit,bool isAsc,Expression<Func<T,type>> OrderByLambda,Expression<Func<T,bool>> whereLambda)
        {
            return Dal.GetModelsByPage(page, limit, isAsc,OrderByLambda, whereLambda);
        }
    }
}
